﻿using DevelopTool.Common;
using System.IO;
using DevelopTool.Forms.BaseForms;
using DevelopTool.Forms.Properties;
using DevelopTool.Forms.LodingForm;

namespace DevelopTool.Forms.ToolForms
{
    /// <summary>
    /// ILSpy嵌入窗口
    /// </summary>
    public partial class ILSpyForm : BaseUIPage
    {
        private string assemblyPath;

        /// <summary>
        /// 程序集路径
        /// </summary>
        public string AssemblyPath
        {
            get
            {
                return this.assemblyPath;
            }
            set
            {
                this.assemblyPath = value;
            }
        }

        private string navigateTo;

        /// <summary>
        /// 定位到类的名称
        /// </summary>
        public string NavigateTo
        {
            get
            {
                return this.navigateTo;
            }
            set
            {
                this.navigateTo = value;
            }
        }

        public ILSpyForm()
        {
            InitializeComponent();
        }

        private void ILSpyForm_Load(object sender,System.EventArgs e)
        {
            string ilspyPath = Path.Combine(GlobalData.AppTempDirectory,"ILSpy","ILSpy.exe");//ILSpy.exe路径

            if(!File.Exists(ilspyPath))
            {
                if(Resources.ILSpy != null && Resources.ILSpy.Length > 0)
                {
                    LoadingHelper.ShowLoading("解压ILSpy",() =>
                    {
                        ZipHelper.DecompressZipFileToDir(Resources.ILSpy,GlobalData.AppTempDirectory);//解压ILSpy压缩包到临时目录
                    });
                }
                else
                {
                    return;
                }
            }

            //嵌入外部程序到本窗口
            new EmbeddedExeHelper().LoadEXE(this,ilspyPath,$"{assemblyPath} /separate /clearList /language:C# {navigateTo}");

        }
    }
}
